package org.nightstudio.common.face.action.bind;

import org.springframework.beans.PropertyAccessException;
import org.springframework.validation.BindingResult;
import org.springframework.validation.DefaultBindingErrorProcessor;
import org.springframework.validation.FieldError;

public class NightStudioBindingErrorProcessor extends
		DefaultBindingErrorProcessor {
	private static String errorCode = new org.nightstudio.common.util.exception.sys.PropertyAccessException().getErrorCode().getValue();
	@Override
	public void processPropertyAccessException(PropertyAccessException ex,
			BindingResult bindingResult) {
		String field = ex.getPropertyChangeEvent().getPropertyName();
		Object value = ex.getPropertyChangeEvent().getNewValue();
		String[] codes = new String[]{errorCode};
		bindingResult.addError(new FieldError(bindingResult.getObjectName(), field,
						value, true, codes, null, ex.getLocalizedMessage()));
	}
	
}
